#include "my_time.h"

const int n = 1000000;
inline double f(double x) { return 4 / (x * x + 1); }

int main() {
  MyTimeI;
  MyTimeA;

  double a = 0.0, b = 1.0, h = (b - a) / n, mypi = 0.0;
  int i;
  mypi = f(a) + f(b);
#pragma omp parallel for private(i) shared(a, h, mypi)
  for (i = 1; i < n; i++) {
#pragma omp critical
    mypi = mypi + f(a + i * h);
  }
  mypi = mypi + (f(a) + f(b)) / 2;
  mypi = h * mypi;

  MyTimeB;
  printf("mypi=%.10f\n", mypi);
  return 0;
}